package com.example.shop.controller;

import com.example.shop.model.req.AddGoodsDTO;
import com.example.shop.model.req.GoodsDTO;
import com.example.shop.model.resp.GoodsDetail;
import com.example.shop.model.resp.GoodsList;
import com.example.shop.service.GoodsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author qwert
 * @version 1.0.0
 * @create 2025/9/2 21:55
 **/
@RestController
@RequestMapping("/api/shop")
@RequiredArgsConstructor
public class GoodsController {
    private final GoodsService goodsService;

    @PostMapping("/add")
    public void addGoods(@RequestBody AddGoodsDTO addGoodsDTO) {
        goodsService.saveGoods(addGoodsDTO);
    }

    @GetMapping("/detail")
    public GoodsDetail getGoodsDetail(@RequestParam("goodsId") String goodsId) {
        return goodsService.getGoodsDetail(goodsId);
    }

    @GetMapping("/list/goods")
    public List<GoodsList> getGoodsList() {
        return goodsService.getGoodsList();
    }


    @PostMapping("/v2/add")
    public void addGoods(@RequestBody GoodsDTO goodsDTO) {
        goodsService.saveGoods(goodsDTO);
//        System.out.println(goodsDTO);
    }

    @GetMapping("/v2/list")
    public List<GoodsList> getGoodsListV2() {
        return goodsService.getGoodsList();
    }

    @GetMapping("/v2/detail")
    public GoodsDetail getGoodsDetailV2(@RequestParam("goodsId") String goodsId) {
        return goodsService.getGoodsDetail(goodsId);
    }

}
